package com.ybkj.daijia.server.zhuanxian;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.util.StringUtils;

public class OrderOrbit implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private Long id;

    private Date created;

    private Date updated;

    private Long orderId;

    @JsonIgnore
    private String xml; // xml 文件,包含坐标信息

    private List<OrderLngLat> lngAndLat = new ArrayList<OrderLngLat>();// 坐标集合

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public String getXml() {
        return xml;
    }

    public void setXml(String xml) {
        this.xml = xml;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public List<OrderLngLat> getLngAndLat() {
        if (!StringUtils.isEmpty(xml)) {
            try {

                lngAndLat = new ArrayList<OrderLngLat>();

                Document doc2 = DocumentHelper.parseText(xml);
                Element root2 = doc2.getRootElement();

                @SuppressWarnings("unchecked")
                Iterator<Element> iter = root2.elementIterator("location");
                while (iter.hasNext()) {
                    Element el = iter.next();
                    OrderLngLat orderLngLat = new OrderLngLat();
                    orderLngLat.setLng(Double.valueOf(el.attributeValue("longitude")));
                    orderLngLat.setLat(Double.valueOf(el.attributeValue("latitude")));
                    lngAndLat.add(orderLngLat);
                }
            } catch (DocumentException e) {
                e.printStackTrace();
            }
        }
        return lngAndLat;
    }

    public void setLngAndLat(List<OrderLngLat> lngAndLat) {
        this.lngAndLat = lngAndLat;
    }

}